package leetcode;

/**
 * 描述:11. 盛最多水的容器
 *
 * @author Madison You
 * @created 23:08
 */
public class Mid_11_MaxArea {

    public static void main(String[] args) {
        int[] arr = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        new Mid_11_MaxArea().maxArea(arr);
    }

    public int maxArea(int[] height) {
        int maxArea = 0;
        int i = 0;
        int j = height.length - 1;
        while (i < j) {
            int h1 = height[i];
            int h2 = height[j];
            int area = (j - i) * Math.min(h1, h2);
            maxArea = Math.max(area, maxArea);
            if (h1 <= h2) {
                i++;
            } else {
                j--;
            }
        }
        return maxArea;
    }

}
